#include "make message.h" void main(void) { messageLine lineOfData; short lineIndex, middle, longest, maxLen, testLen, loop, highError, highHelp, clearing; winMsgLine array[MAXNUMMESWINLINES] = {NULL}; int winLength = 0, winWidth[2] = {NULL}, looping = 0; lineIndex = 0; testLen = 0; ifstream sourceText("message.source"); fstream messageFile; do { lineIndex++; sourceText >> lineOfData.messageNo; sourceText.get(); sourceText >> lineOfData.helpCode; sourceText.get(); sourceText >> lineOfData.width; sourceText.get(); sourceText.getline(lineOfData.holdLine, 3000); if(lineOfData.messageNo == NULL) break; if(lineIndex == 1) highError = lineOfData.messageNo; testLen = (strlen(lineOfData.holdLine)); if(testLen > longest) longest = testLen; if(lineOfData.messageNo == 32767) { middle = lineIndex; } }while(!sourceText.eof()); highHelp = lineOfData.messageNo; maxLen = longest + (sizeof(short)*3); sourceText.close(); if(longest > 3000) { cls(); cout << endl << "\tThere appear to be more characters in the input string" << endl << "\tthan this program was designed to handle" << endl << endl << "\tPlease check to insure that your input file has" << endl << "\tlines of (one) identifying integer, (one) help ID" << endl << "\tand a string of up to (3000) characters." << endl << endl << "\tPlease press 'Return' to continue. "; cin.get(); exit(1); } //end if lineIndex -= 1; sourceText.open("message.source"); messageFile.open("ccc.messages",ios::out | ios::binary); messageFile.seekg(0, ios::beg); messageFile.write((char *)&maxLen, 8); messageFile.write((char *)&middle, 4); messageFile.write((char *)&highError, 4); messageFile.write((char *)&highHelp, 4); for(loop = 1;loop <= lineIndex;loop++) { for(clearing = 0; clearing < MAXMSGLINE; clearing++) lineOfData.holdLine[clearing] = NULL; sourceText >> lineOfData.messageNo; sourceText.get(); sourceText >> lineOfData.helpCode; sourceText.get(); sourceText >> lineOfData.width; sourceText.get(); sourceText.getline(lineOfData.holdLine, 3000); messageFile.write((char *)&lineOfData,maxLen); } messageFile.close(); sourceText.close(); maxLen = middle = highError = highHelp = 0; //from this point, it's for testing purposes. messageFile.open("ccc.messages",ios::in | ios::binary); messageFile.seekg(0, ios::beg); messageFile.read((char *)&maxLen, 8); messageFile.read((char *)&middle, 4); messageFile.read((char *)&highError, 4); messageFile.read((char *)&highHelp, 4); cls(); cout << endl << "\tThe length of the longest line = " << longest << endl << "\tThe 'middle' line# = " << middle << endl << "\tThe largest Error Value = " << highError << endl << "\tThe largest Help Value = " << highHelp << endl; messageFile.close(); cout << endl << endl << "\tPress a key to continue. "; cin.get(); int number = 1; int middleByte; while(number) { cls(); cout << endl << "\tNow is the time to test the random access part!" << endl << endl << "\tPlease type the Message Number of the desired message" << endl << "\t(valid ones, Tim! :)" << endl << "\tor enter '999999' to exit "; cin >> number; if(number==999999) { cout << endl << "\t"; exit(0); } cin.get(); if((number >= highError) && (number <= highHelp)) { messageFile.open("ccc.messages",ios::in | ios::binary); messageFile.seekg(0, ios::beg); messageFile.read((char *)&maxLen, 8); messageFile.read((char *)&middle, 4); messageFile.read((char *)&highError, 4); messageFile.read((char *)&highHelp, 4); middleByte = (maxLen*(middle-1))+20; messageFile.seekg(middleByte, ios::beg); messageFile.seekg((maxLen*(number)), ios::cur); messageFile.read((char *)&lineOfData,maxLen); messageFile.close(); winWidth[0] = (int)lineOfData.width; winLength = FormatWindow(lineOfData.holdLine, array, winWidth); lineOfData.width = (short)winWidth[0]; cls(); cout << endl << "\tFor line #" << lineOfData.messageNo << ", we have a help line value of " << lineOfData.helpCode << ", " << endl << "\ta width value of " << lineOfData.width << ", " << endl << "\tand a text message of : " << endl; for(looping = 1; looping <= winLength; looping++) { cout << "\t" << array[looping] << endl; } cout << endl << endl << "\tPress 'Return' to continue. "; cin.get(); } } } void cls(void) { system("cls"); } int FormatWindow(char * string, winMsgLine array[], int * width) { char * tempptr = string; int stringlen = strlen(string); int looping = 1, terminator = 0, endWidth = 0, innerLoop = 0, middle = 0, tempLoop = 0; bool done = false, newLine = false, center = false; winMsgLine tempLine = {NULL}; char * charptr = NULL; do{ strncpy(array[looping], tempptr, *width); for(innerLoop = 0; ((innerLoop < *width) && (!done)) && (!newLine); innerLoop++) { terminator++; if(*tempptr == '~') // new line { array[looping][innerLoop] = 32; newLine = true; } if(*tempptr == '^') //center the line { array[looping][innerLoop] = 32; center = true; } tempptr++; if(*tempptr == NULL) done = true; } if(center) { array[looping][terminator] = NULL; strncpy(tempLine, array[looping], terminator); tempLine[(terminator + 1)] = NULL; middle = ((int)((*width - terminator) / 2)); for(tempLoop = 0; tempLoop < middle; tempLoop++) array[looping][tempLoop] = 32; charptr = &array[looping][tempLoop]; strcpy(charptr, tempLine); terminator += middle; center = false; } if(!done) { while((*tempptr != 32) && (*tempptr != NULL) && (*tempptr != '~')) { tempptr--; terminator--; } } array[looping][terminator] = NULL; terminator++; if(terminator > endWidth) endWidth = terminator; terminator = 0; looping++; tempptr++; newLine = false; }while(tempptr-string < stringlen); looping--; *width = endWidth; return(looping); }